//
//  FriendsTableViewController.m
//  ChatLine
//
//  Created by 小灰灰的pro on 16/3/22.
//  Copyright © 2016年 小灰灰. All rights reserved.
//

//********** 通讯录界面 **********//

#import "FriendsTableViewController.h"
#import "AddbuddyViewController.h"
#import "registerViewController.h"
#import "AccountregistrationVController.h"
#import "PrefixHeader.pch"
#import "LCTableViewCell.h"

#import "Theuser.h"
@interface FriendsTableViewController ()<UINavigationControllerDelegate>

@property (nonatomic, strong) NSString *userobjectId;

@end

@implementation FriendsTableViewController



- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    self.navigationItem.title = @"通讯录";
    
    [self.tableView registerClass:[LCTableViewCell class] forCellReuseIdentifier:@"cell"];
    //注册按钮
        self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"注册" style:(UIBarButtonItemStyleDone) target:self action:@selector(leftBT)];
    
    //设置添加好友按钮
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"barbuttonicon_add_cube@3x"] style:(UIBarButtonItemStyleDone) target:self action:@selector(rightBT)];
    
    self.tableView.tableFooterView = [[UIView alloc]init];
    


    AVQuery *query = [AVQuery queryWithClassName:@"_User"];
    [query whereKey:@"username" hasPrefix:@""];
    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
        NSArray<AVObject *> *array = objects;
        
        NSLog(@"%ld",array.count);
        
        for (NSDictionary *dic in array)
        {
            NSString *title = [dic valueForKey:@"username"];
            NSLog(@"%@",title);
            
            Theuser *TheUser = [[Theuser alloc]init];
            
        }
        
    }];
    
}



//***** 注册按钮方法 *****//
- (void)leftBT{
    
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"请选择注册方式" preferredStyle:UIAlertControllerStyleAlert];
    [self presentViewController:alert animated:YES completion:^{
    }];
    UIAlertAction *phone = [UIAlertAction actionWithTitle:@"手机号注册(推荐)" style:(UIAlertActionStyleDestructive) handler:^(UIAlertAction * _Nonnull action)
    {
        UINavigationController *RegisterVC = [[UINavigationController alloc]initWithRootViewController:[[registerViewController alloc]init]];
        [self presentViewController:RegisterVC animated:YES completion:nil];
    }];
    
    
    UIAlertAction *account = [UIAlertAction actionWithTitle:@"账号注册" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action)
    {
        UINavigationController *AccountregistrationVC = [[UINavigationController alloc]initWithRootViewController:[[AccountregistrationVController alloc]init]];
        [self presentViewController:AccountregistrationVC animated:YES completion:nil];
    }];
    
    
    UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:(UIAlertActionStyleCancel) handler:^(UIAlertAction * _Nonnull action)
    {
                                  
    }];
    [alert addAction:phone];
    [alert addAction:account];
    [alert addAction:cancel];
    
    
    
    
    
}
//***** 添加好友按钮方法 *****//
- (void)rightBT{
    AddbuddyViewController *AddbuddyVC = [[AddbuddyViewController alloc]init];
    [self.navigationController pushViewController:AddbuddyVC animated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - 设置section
//***** section的头部高度 *****//
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 30;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 10;
}
//***** cell的高度 *****//
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 50;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    LCTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    
    if (!cell)
    {
        cell = [[LCTableViewCell alloc]initWithStyle:(UITableViewCellStyleValue1) reuseIdentifier:@"cell"];
    }
    
    return cell;
}
//***** cell跳转 *****//
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSLog(@"点击了 %ld",indexPath.row);
}




/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
